package thread_pool;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/5/23
 * Time:9:23
 * 原始创建线程池的方法1
 **/
public class PoolDemo11 {
    public static void main(String[] args) {
        //原始创建线程池的方法

        ThreadPoolExecutor executor = new ThreadPoolExecutor(5,
                10,60, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(1000));//一定要给任务队列设置容量

        for (int i = 0; i < 2; i++) {//只创建了2个线程

            executor.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("线程名称" + Thread.currentThread().getName());
                }
            });
        }
    }
}
